<template>
	<view v-if="img_items.length > 0">
		<!-- 搜索栏 -->
		<view class="search">
			<uni-search-bar class="search_bar" placeholder="品质保障,安心家装" @confirm="search" @cancel="cancel"
				cancel-text="取消">
				<uni-icons slot="searchIcon" size="16" type="search" />
			</uni-search-bar>
		</view>

		<!-- 轮播图 -->
		<view class="swiper_content">
			<swiper class="swiper" autoplay circular indicator-dots indicator-color="rgba(255,255,255,0.5)"
				indicator-active-color="rgba(255,255,255,1)">
				<swiper-item>
					<view class="swiper-item">
						<image src="../../static/img/banner1.png"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item">
						<image src="../../static/img/banner2.png"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item">
						<image src="../../static/img/banner3.png"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>

		<!-- 选项卡 -->
		<view class="tab">
			<view class="tab_nav">
				<text :class="{tab_nav_text:current == index}" v-for="(item,index) in items" :key="item.index"
					@click="onClickItem(index)">{{item.title}}</text>
			</view>
			<view class="tab_content">
				<view v-show="current === 0">
					<view class="tab_content_box">
						<view class="tab_content_list" v-for="(item,index) in img_items" :key="item.index">
							<image :src="item.src" mode="widthFix"></image>
							<view class="tab_content_info">
								<text class="tab_content_info_title">{{item.title}}</text>
								<text class="tab_content_info_text">{{item.text}}</text>
								<view class="tab_content_info_money">
									<text>￥{{item.money}}</text>
									<uni-icons type="cart" @click="addGoods(item)" size="16" class="icons" color="#fff"></uni-icons>
								</view>

							</view>
						</view>
					</view>
					<view class="remind">没有内容了</view>
				</view>
				<view v-show="current === 1">
					<view class="tab_content_box">
						<view class="tab_content_list" v-for="(item,index) in bed_items" :key="item.index">
							<image :src="item.src" mode="widthFix"></image>
							<view class="tab_content_info">
								<text class="tab_content_info_title">{{item.title}}</text>
								<text class="tab_content_info_text">{{item.text}}</text>
								<view class="tab_content_info_money">
									<text>￥{{item.money}}</text>
									<uni-icons type="cart" @click="addGoods(item)" size="16" class="icons" color="#fff"></uni-icons>
								</view>
							</view>
						</view>
					</view>
					<view class="remind">没有内容了</view>
				</view>
				<view v-show="current === 2">
					<view class="tab_content_box">
						<view class="tab_content_list" v-for="(item,index) in lamp_items" :key="item.index">
							<image :src="item.src" mode="widthFix"></image>
							<view class="tab_content_info">
								<text class="tab_content_info_title">{{item.title}}</text>
								<text class="tab_content_info_text">{{item.text}}</text>
								<view class="tab_content_info_money">
									<text>￥{{item.money}}</text>
									<uni-icons type="cart" @click="addGoods(item)" size="16" class="icons" color="#fff"></uni-icons>
								</view>
							</view>
						</view>
					</view>
					<view class="remind">没有内容了</view>
				</view>
				<view v-show="current === 3">
					<view class="tab_content_box">
						<view class="tab_content_list" v-for="(item,index) in life_items" :key="item.index">
							<image :src="item.src" mode="widthFix"></image>
							<view class="tab_content_info">
								<text class="tab_content_info_title">{{item.title}}</text>
								<text class="tab_content_info_text">{{item.text}}</text>
								<view class="tab_content_info_money">
									<text>￥{{item.money}}</text>
									<uni-icons type="cart" @click="addGoods(item)" size="16" class="icons" color="#fff"></uni-icons>
								</view>
							</view>
						</view>
					</view>
					<view class="remind">没有内容了</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tabData from '../../static/js/data.js'
	export default {
		data() {
			return {
				swiperItem: [],
				items: [{
					title: "Roca乐家",
				}, {
					title: "Annwa床",
				}, {
					title: "HUIDA灯具",
				}, {
					title: "Life装修",
				}],
				current: 0,
				img_items: tabData.data.img_items,
				lamp_items: tabData.data.lamp_items,
				bed_items: tabData.data.bed_items,
				life_items: tabData.data.life_items,
			}
		},
		methods: {
			onClickItem(e) {
				this.current = e
			},
			addGoods(data){
				console.log(data);
				tabData.data.goods_items.push({
					src: data.src,
					title: data.title,
					text: data.text,
					money: data.money,
					num:1
				})
				console.log(tabData.data.goods_items);
				
			},
			cancel() {
				console.log("取消");
			},
			search() {
				console.log("搜索");
			}
		},
		onLoad() {
			uni.showLoading({
				title: '查询中...'
			})
			uniCloud.callFunction({
				name: 'selectImage',
				success: (res) => {
					// console.log(res);
					this.swiperItem = res.result.data

				},
				fail(e) {
					console.log(e)
				},
				complete: () => {
					uni.hideLoading()
				}
			})
		}
	}
</script>

<style lang="scss" scoped>
	// 搜索栏
	.search {
		width: 750rpx;
		box-sizing: border-box;
	}

	// 轮播图
	.swiper_content {
		.swiper {
			// height: 300rpx;
			margin: 20rpx;

			.swiper-item {
				height: 100%;
				box-sizing: border-box;

				image {
					border-radius: 10rpx;
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	// 选项卡
	.tab {

		.tab_nav {
			display: flex;
			justify-content: space-evenly;

			text {
				font-size: 30rpx;
				padding: 30rpx 0;
				color: #333;
			}

			.tab_nav_text {
				color: $color;
			}
		}

		.tab_content {
			padding: 20rpx;
			box-sizing: border-box;

			.tab_content_box {
				display: flex;
				flex-wrap: wrap;

				.tab_content_list {
					width: 50%;
					padding: 10rpx;
					box-sizing: border-box;

					image {
						display: block;
						width: 100%;
						border-radius: 10rpx;
					}

					.tab_content_info {
						font-size: 34rpx;
						display: flex;
						flex-direction: column;
						background: rgb(246, 246, 248);
						border-bottom-left-radius: 10rpx;
						border-bottom-right-radius: 10rpx;

						.tab_content_info_title {
							padding: 10rpx;
							color: #000;
						}

						.tab_content_info_text {
							font-size: 24rpx;
							padding-left: 10rpx;
							color: #999;
						}

						.tab_content_info_money {
							padding: 10rpx;
							color: $color;
							font-weight: bold;
							display: flex;
							justify-content: space-between;
							align-items: center;
							.uni-icons {
								display: flex;
								align-items: center;
								justify-content: center;
								padding: 10rpx;
								background: $color;
								border-radius: 50rpx;
								font-size: 16rpx;
							}
						}
					}
				}
			}

			.remind {
				padding: 20rpx 0;
				text-align: center;
				font-size: 24rpx;
				color: $color;
			}
		}
	}
</style>
